package com.taiyi.renaissancemall.ui.classification;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.taiyi.renaissancemall.R;
import com.taiyi.renaissancemall.Utils.ActivityUtils;
import com.taiyi.renaissancemall.base.MyApp;
import com.taiyi.renaissancemall.bean.NextClassBean;
import com.taiyi.renaissancemall.ui.MainActivity;
import com.taiyi.renaissancemall.ui.classification.goodlist.GoodListActivity;
import com.taiyi.renaissancemall.ui.main.goodsdetail.GoodsDetailActivity;

import java.util.List;

//右边二级
public class NextClassAdapter2 extends BaseQuickAdapter<NextClassBean.ClassificationlistBeanX.ClassificationlistBean, BaseViewHolder> {
    private OnSetClickListener onSetViewClickListener;
    private RequestOptions requestOptions = new RequestOptions();

    public interface OnSetClickListener {
        void onSetViewClick(View v, int position);
    }

    public void setOnSetViewClickListener(OnSetClickListener listener) {
        this.onSetViewClickListener = listener;
    }

    public NextClassAdapter2(int layoutResId, List<NextClassBean.ClassificationlistBeanX.ClassificationlistBean> classificationlistBeans) {
        super(layoutResId, classificationlistBeans);
    }

    @Override
    protected void convert(BaseViewHolder viewHoder, NextClassBean.ClassificationlistBeanX.ClassificationlistBean item) {
        viewHoder.setText(R.id.tv_next2, item.name);
        ImageView img = viewHoder.getView(R.id.img_next2);
        requestOptions.skipMemoryCache(true);
        requestOptions.placeholder(R.mipmap.class_child_child_item_test_iv);
        requestOptions.diskCacheStrategy(DiskCacheStrategy.RESOURCE).dontAnimate();
        Glide.with(MyApp.getInstance()).asDrawable().load(item.imgurl).apply(requestOptions).into(new SimpleTarget<Drawable>() {
            @Override
            public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
//                //原始图片宽高
//                int imageWidth = resource.getIntrinsicWidth();
//                int imageHeight = resource.getIntrinsicHeight();
//                //按比例收缩图片
//                float ratio = (float) ((imageWidth * 1.0) / (200 * 1.0));
//                int height = (int) (imageHeight * 1.0 / ratio);
//                ViewGroup.LayoutParams params = img.getLayoutParams();
//                params.width = 200;
//                params.height = height;
                if (resource != null)
                    img.setImageDrawable(resource);
            }
        });
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //跳转分类商品列表
                Intent intent = new Intent(mContext, GoodListActivity.class);
                intent.putExtra("next_class_2_id", item.classificationid + "");
                intent.putExtra("next_class_2_name", item.name);
                intent.putExtra("labelId", "");
                intent.putExtra("categoryid", "");
                mContext.startActivity(intent);
            }
        });
    }

}
